package io.kimmking.auth2.unit;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResultV1 <T> implements Serializable {

    private T datas;
    private Integer resp_code;
    private String resp_msg;

    public static <T> ResponseResultV1<T> succeed(String msg) {
        return of(null, CodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> ResponseResultV1<T> succeed(T model, String msg) {
        return of(model, CodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> ResponseResultV1<T> succeed(T model) {
        return of(model, CodeEnum.SUCCESS.getCode(), "");
    }

    public static <T> ResponseResultV1<T> of(T datas, Integer code, String msg) {
        return new ResponseResultV1<>(datas, code, msg);
    }

    public static <T> ResponseResultV1<T> failed(String msg) {
        return of(null, CodeEnum.ERROR.getCode(), msg);
    }

    public static <T> ResponseResultV1<T> failed(T model, String msg) {
        return of(model, CodeEnum.ERROR.getCode(), msg);
    }

    private enum CodeEnum {
        SUCCESS(0),
        ERROR(1);

        private Integer code;
        CodeEnum(Integer code){
            this.code = code;
        }

        public Integer getCode() {
            return code;
        }
    }
}
